package com.xukai.springboot.util.common;

import com.sun.deploy.util.StringUtils;
import com.xukai.springboot.util.encrypt.Encrypt;

import java.util.Arrays;


public class Common {


    private static Common instance;

    public static Common getInstance() {
        if (instance == null) {
            synchronized (Common.class) {
                if (instance == null) {
                    instance = new Common();
                }
            }
        }
        return instance;
    }

    /**
     * 验证签名
     *
     * @param sign
     * @param parames
     * @return
     */
    public boolean checkSign(String sign, int isDebug, String... parames) {
        if (1 == isDebug) {
            return true;
        }
        if (sign == "") {
            return false;
        }
        if (parames.length == 0) {
            return false;
        }
        String param = StringUtils.join(Arrays.asList(parames), ",");
        String paramMd5 = new Encrypt().MD5(param);
        if (!sign.equals(paramMd5)) {
            return false;
        }
        return true;
    }


}
